/**
 * 
 */
package org.swing.table.filter;

import org.swing.table.imp.TextFilter;

/**
 * @author lqnhu
 *
 */
public class SimpleTextFilter extends AbstractTextFilter {
	private final TextFilter delegate;

	public SimpleTextFilter(TextFilter delegate, FilterTrigger trigger) {
		super();
		this.delegate = delegate;
		if (trigger == FilterTrigger.ON_CHANGE) {
			this.getTextField().getDocument()
					.addDocumentListener(new FilterOnDocumentChangeListener());
		} else if (trigger == FilterTrigger.ON_ENTER) {
			this.getTextField().addKeyListener(new FilterOnEnterKeyListener());
		} else {
			throw new IllegalArgumentException("Invalid trigger " + trigger);
		}
	}

	public boolean filter(Object value) {
		return this.delegate.filter(value, this.getTextField().getText());
	}

	public static enum FilterTrigger {
		ON_CHANGE, ON_ENTER
	}
}
